package com.wzz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wzz.annotation.Cache;
import com.wzz.entity.Coll;
import com.wzz.exception.BusinessException;
import com.wzz.exception.CommonErrorCode;
import com.wzz.mapper.CollMapper;
import com.wzz.mapper.NoticeMapper;
import com.wzz.service.CollService;
import com.wzz.service.NoticeService;
import com.wzz.utils.CommonUtils;
import com.wzz.utils.RedisUtil;
import com.wzz.vo.PageResponse;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author by liutao
 * @implNote 10/20 9:05
 */
@Service
@RequiredArgsConstructor
public class CollServiceImpl extends ServiceImpl<CollMapper, Coll> implements CollService {

    private final CollMapper collMapper;

    private final RedisUtil redisUtil;

    @Override
    public PageResponse<Coll> getAllColl(Coll coll) {
        IPage<Coll> collIPage = new Page<>(coll.getPageNo(), coll.getPageSize());
//        LambdaQueryWrapper<Coll> wrapper = new LambdaQueryWrapper<>();
        QueryWrapper<Coll> wrapper = new QueryWrapper<>();
        if(coll.getContent()!=null && StringUtils.isNotBlank( coll.getContent())){
            wrapper.lambda().like(Coll::getContent,coll.getContent());
        }
        if(coll.getType()!=null && StringUtils.isNotBlank( coll.getType())){
            wrapper.lambda().eq(Coll::getType,coll.getType());
        }
        if(coll.getName()!=null && StringUtils.isNotBlank( coll.getName())){
            wrapper.lambda().like(Coll::getName,coll.getName());
        }
        if(coll.getUname()!=null && StringUtils.isNotBlank( coll.getUname())){
            wrapper.lambda().like(Coll::getUname,coll.getUname());
        }
        if(coll.getUserid()!=null ){
            wrapper.lambda().eq(Coll::getUserid,coll.getUserid());
        }
        if(coll.getDataid()!=null ){
            wrapper.lambda().eq(Coll::getDataid,coll.getDataid());
        }
        wrapper.lambda().orderByDesc(Coll::getId);
//        CommonUtils.setLikeWrapper(wrapper, Collections.singletonMap("content", content));
//        wrapper.orderByDesc("id",  "ctime");

        collIPage = collMapper.selectPage(collIPage, wrapper);

        return PageResponse.<Coll>builder().data(collIPage.getRecords()).total(collIPage.getTotal()).build();
    }
}
